<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        <ul class="nav nav-tabs" data-field="type">
            <li class="active"><a href="#one" data-toggle="tab">积分统计</a></li>
        </ul>
    </div>
    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <!-- 权益积分信息 -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">权益积分信息</h4>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>平台当前总锁仓权益积分总额：</label>
                                    <span id="total-locked" class="text-primary font-weight-bold">20000</span>
                                    <label class="ml-4">平台当前可用权益积分总额：</label>
                                    <span id="total-available" class="text-success font-weight-bold">2000000</span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>平台当前已使用权益积分总额：</label>
                                    <span id="total-used" class="text-info font-weight-bold">20000</span>
                                    <label class="ml-4">平台当前待到账权益积分总额：</label>
                                    <span id="total-pending" class="text-warning font-weight-bold">20000</span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>权益积分转换金额比例：</label>
                                    <span id="exchange-ratio" class="config-value">0.8</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('exchange_ratio', '权益积分转换金额比例')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('exchange_ratio')">操作记录</button>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>提现费率：</label>
                                    <span id="withdraw-fee" class="config-value">0.8</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('withdraw_fee', '提现费率')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('withdraw_fee')">操作记录</button>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>权益有效期天数：</label>
                                    <span id="valid-days" class="config-value">200</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('valid_days', '权益有效期天数')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('valid_days')">操作记录</button>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>权益积分释放比例：</label>
                                    <span id="release-ratio" class="config-value">0.8</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('release_ratio', '权益积分释放比例')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('release_ratio')">操作记录</button>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>绿色积分释放比例：</label>
                                    <span id="green-release-ratio" class="config-value">0.8</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('green_release_ratio', '绿色积分释放比例')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('green_release_ratio')">操作记录</button>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>权益凭证最大额度：</label>
                                    <span id="certificate-max" class="config-value">200000</span>
                                    <button type="button" class="btn btn-primary btn-sm ml-2" onclick="showEditModal('certificate_max', '权益凭证最大额度')">修改</button>
                                    <button type="button" class="btn btn-default btn-sm ml-1" onclick="operateConfig('certificate_max')">操作记录</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 绿色积分信息 -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">绿色积分信息</h4>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>平台当前可用绿色积分总额：</label>
                                    <span id="green-total-available" class="text-success font-weight-bold">2000000</span>
                                    <label class="ml-4">平台当前已使用绿色积分总额：</label>
                                    <span id="green-total-used" class="text-info font-weight-bold">20000</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 修改配置弹窗 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">修改比例</h4>
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label id="modal-label">修改比例：</label>
                    <input type="number" step="0.01" class="form-control" id="modal-input" placeholder="请输入新的值">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmUpdate()">确定</button>
            </div>
        </div>
    </div>
</div>

<script>
$(function() {
    // 页面加载时获取数据
    loadData();
});

// 加载数据
function loadData() {
    Fast.api.ajax({
        url: 'finance/index',
        type: 'GET',
        dataType: 'json'
    }, function(data, ret) {
        if (ret.code === 1) {
            // 更新权益积分信息
            $('#total-locked').text(ret.data.equity.total_locked);
            $('#total-available').text(ret.data.equity.total_available);
            $('#total-used').text(ret.data.equity.total_used);
            $('#total-pending').text(ret.data.equity.total_pending);
            $('#exchange-ratio').text(ret.data.equity.exchange_ratio);
            $('#withdraw-fee').text(ret.data.equity.withdraw_fee);
            $('#valid-days').text(ret.data.equity.valid_days);
            $('#release-ratio').text(ret.data.equity.release_ratio);
            $('#green-release-ratio').text(ret.data.equity.green_release_ratio);
            $('#certificate-max').text(ret.data.equity.certificate_max);
            
            // 更新绿色积分信息
            $('#green-total-available').text(ret.data.green.total_available);
            $('#green-total-used').text(ret.data.green.total_used);
        }
    });
}

// 当前编辑的配置类型
var currentEditType = '';

// 显示编辑弹窗
function showEditModal(type, label) {
    currentEditType = type;
    var fieldMap = {
        'exchange_ratio': '#exchange-ratio',
        'withdraw_fee': '#withdraw-fee',
        'valid_days': '#valid-days',
        'release_ratio': '#release-ratio',
        'green_release_ratio': '#green-release-ratio',
        'certificate_max': '#certificate-max'
    };
    
    var currentValue = $(fieldMap[type]).text();
    $('#modal-label').text('修改' + label + '：');
    $('#modal-input').val(currentValue);
    $('#editModal').modal('show');
}

// 确认更新
function confirmUpdate() {
    var value = $('#modal-input').val();
    
    if (!value || value <= 0) {
        Toastr.error('请输入有效值');
        return;
    }
    
    var params = {};
    params[currentEditType] = value;
    
    Fast.api.ajax({
        url: 'finance/updateEquityConfig',
        type: 'POST',
        data: params
    }, function(data, ret) {
        if (ret.code === 1) {
            Toastr.success('配置更新成功');
            $('#editModal').modal('hide');
            loadData(); // 重新加载数据
        } else {
            Toastr.error(ret.msg || '配置更新失败');
        }
    });
}

// 操作记录（暂时用提示代替）
function operateConfig(type) {
    Toastr.info('操作记录功能待开发');
}
</script>

<style>
.font-weight-bold {
    font-weight: bold;
    font-size: 16px;
}
.ml-4 {
    margin-left: 2rem;
}
.text-primary {
    color: #007bff !important;
}
.text-success {
    color: #28a745 !important;
}
.text-info {
    color: #17a2b8 !important;
}
.text-warning {
    color: #ffc107 !important;
}
.panel-title {
    color: #333;
    font-weight: bold;
}
.form-group label {
    font-weight: normal;
    margin-right: 10px;
}
.config-value {
    font-weight: bold;
    color: #007bff;
    font-size: 16px;
    margin-right: 10px;
}
.ml-1 {
    margin-left: 0.25rem;
}
.ml-2 {
    margin-left: 0.5rem;
}
</style>